package indi.zhifa.study2024.nbr.monitor.util;

import indi.zhifa.study2024.nbr.monitor.gen.monitor.sys.po.GenMonitorSysDbEntity;
import indi.zhifa.study2024.nbr.monitor.gen.monitor.sys.service.IGenMonitorSysDbDbService;
import indi.zhifa.study2024.nbr.monitor.properties.DbProperties;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@RequiredArgsConstructor
@Component
public class DbEntityMemo {

    private final DbProperties mDbProperties;

    int mCurDbIndex;

    @PostConstruct
    public void init(){
        mCurDbIndex = 0;
    }

    synchronized public String genDbCode(){
        String rtn = mDbProperties.getEnterprise().get(mCurDbIndex);
        mCurDbIndex++;
        if(mCurDbIndex >= mDbProperties.getEnterprise().size()){
            mCurDbIndex = 0;
        }
        return rtn;
    }

}
